	$(function() {
		//活动结束
		$("#join").hide();
		$("#envelopeEnd").show();	
		
		$('#share_btn').click(function() {
			$('.share-layer').fadeIn();
		});
		$('.share-layer').click(function() {
			$(this).hide();
		})
		Util.jTab = function(tab, pan, evt) {
			$(pan).find('.jPanel').hide();
			$(tab).find('.jTab:first').addClass('current').show();
			$(pan).find('.jPanel:first').show();
			$(tab).find('.jTab').bind(
					evt,
					function() {
						$(this).addClass('current').siblings('.jTab')
								.removeClass('current');
						var index = $(tab).find('.jTab').index(this);
						$(pan).children().eq(index).show().siblings().hide();
						var tool = $('#ToolTip');
						if (typeof (tool[0]) != 'undefined') {
							tool.remove()
						}
						;
						return false
					})
		};
		Util.jTab('#investTabs', '#investPanel', 'click');

		//领取红包
		$('#receive_btn').unbind('click').bind('click',function() {
			var param = {};
			param["paramMap.senvKey"] = $("#senvKey").val();
			param["paramMap.mobilePhone"] = $("#input_tel").val();
			if(checkMobilefor()){
				$.ajax({
		            dataType: 'json',
		            url: environment.basePath+"/wlcShareReceive.do",
		            data: param,
		            async:false,
		            type: 'POST',
		            success: function(data) {
		            	if (data.msg == 'success') {
		            		$("#successReceivedMsg").html('成功抢到' + data.valMoney + '元，立即使用<br>收益全归你');
		            		$("#join").hide();
							$("#successReceived").show();
						}else if (data.msg == 'hasReceived') {
							$("#hasReceivedMsg").html('你已抢过该红包<br>抢到金额为' + data.valMoney + '元');
							$("#join").hide();
							$("#hasReceived").show();
							if(data.receivedStatus == 1){
								$("#hr_tyj_btn").show();
							}else{
								$("#hr_tyj_btn").hide();
							}
						} else if (data.msg == 'spliteEnvelopeDead') {
							$("#join").hide();
							$("#envelopeDead").show();
						}else if (data.msg == 'isOver') {
							$("#join").hide();
							$("#envelopeOver").show();
						}else if (data.msg == 'LimitExceeded') {
							$("#join").hide();
							$("#LimitExceeded").show();
						}else if (data.msg == 'register') {
							var urlStr = '/getRedEnvelopesInit.do?mobile=' + $("#input_tel").val();
							urlStr = urlStr + '&senvKey=' + $("#senvKey").val();
							$("#registerReceivedMsg").html('成功抢到' + data.valMoney + '元，立即使用<br>收益全归你');
							$('#register_btn').attr('href',urlStr); 
		            		$("#join").hide();
							$("#registerReceived").show();
						}else if (data.msg == 'envelopeEnd') {
							$("#join").hide();
							$("#envelopeEnd").show();
						} else {
							alert(data.msg);
						}
		            },
					error : function(data) {
						console.log(data);
					}
		        }); 
			}
		});

		$(".answer_msg").each(function(){
			$(this).text(getResultMsg(Math.floor(Math.random()*4 + 1)));
		})

	})
	
	function getResultMsg(data){
    	switch(data){
    		case 5: return "摩擦摩擦，不停下抢红包的步伐"; break;
        	case 4: return "抢完，我还是安静的美男子"; break;
        	case 3: return "不谢，路过而已"; break;
        	case 2: return "抢完，约吗"; break;
       	 	case 1: return "带我抢红包带我灰"; break;
        	default: return "世界这么大，抢完红包，我就有money出去走走了"; break;
    	}
	}
	
	// 验证规则
	var authRules = {
		isMobile : function(str) {
			return new RegExp(authRegExp.mobile).test(str);
		}
	};
	
	var authRegExp = {
			mobile : "^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$", // 手机
	};
	
	function checkMobilefor() {
		var rsMobile = false;
		var mobile = $("#input_tel").val();
		if (mobile == "" || mobile == null) {
			alert("请输入您的手机号码");
			return rsMobile;
		}
		if (mobile.length != 11) {
			alert("请输入11位手机号码");
			return rsMobile;
		} else if (!authRules.isMobile(mobile)) {
			alert("手机号码不正确");
			return rsMobile;
		}else {
			rsMobile = true;
			return rsMobile;
		}
	}
